package com.ukao.pad.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.percent.PercentRelativeLayout;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.pad.R;
import com.ukao.pad.bean.OrderInformationBean;
import com.ukao.pad.utils.DateUtils;

import java.util.Date;
import java.util.List;

/**
 * Created by kefu001 on 2018/5/18.
 * 订单衣物列表适配器
 */

public class OrderClothingListAdapter extends CommonAdapter<OrderInformationBean.ProductListBean> {
    private final  static int ADJUNCT=2;  //附件
    private Context context;
    private String codeNo;
    public OrderClothingListAdapter(Context context, List<OrderInformationBean.ProductListBean> datas) {
        super(context, datas, R.layout.adapter_order_clothing_list_item);
        this.context=context;
    }


    @Override
    public void convert(ViewHolder viewHolder, OrderInformationBean.ProductListBean productListBean) {
        PercentRelativeLayout  MyPercentLayout=viewHolder.getView(R.id.MyPercentLayout);
        TextView tvProductName=viewHolder.getView(R.id.product_name);//产品名
       TextView  tvClothingCode =viewHolder.getView(R.id.tv_clothing_code); //衣服码
       TextView tvConveyType =viewHolder.getView(R.id.tv_convey_type);   //输送线
       TextView tvPassProcess= viewHolder.getView(R.id.tv_pass_process);  //经过的过程
       TextView tvOperator= viewHolder.getView(R.id.tv_operator);   //操作员
        tvProductName.setText(productListBean.getProductName()+"");
        if(productListBean.getType()==ADJUNCT) {
            Drawable drawableRight = context.getResources().getDrawable(
                    R.drawable.adjunct);
            tvProductName.setCompoundDrawablesWithIntrinsicBounds(null, null, drawableRight, null);
        }else {
            tvProductName.setCompoundDrawablesWithIntrinsicBounds(null,null,null,null);
        }
        if(!TextUtils.isEmpty(productListBean.getBindAliasCode())){
            tvClothingCode.setText(productListBean.getBindAliasCode());
        }else if(!TextUtils.isEmpty(productListBean.getBindCode())){
            tvClothingCode.setText(productListBean.getBindCode());
        }else if(!TextUtils.isEmpty(productListBean.getScanCode())){
            tvClothingCode.setText(productListBean.getScanCode());
        }else {
            tvClothingCode.setText("");
        }
//        if(codeNo.equals(tvClothingCode.getText().toString())){
//              //等于其中代码就是选中
//            MyPercentLayout.setBackgroundColor(Color.parseColor("#564013"));
//        }else {
//            //没有等于就是默认颜色
//            MyPercentLayout.setBackgroundColor(Color.parseColor("#222222"));
//        }
        tvConveyType.setText("输"+productListBean.getTranNum()); //运输线
        //设置经过步骤
        if(!TextUtils.isEmpty(productListBean.getStatusText())){
            if(productListBean.getStatusText().trim().equals("已洗完")){
                tvPassProcess.setTextColor(mContext.getResources().getColor(R.color.green));
            }else if(productListBean.getStatusText().trim().equals("洗涤中")){
                tvPassProcess.setTextColor(mContext.getResources().getColor(R.color.warm_red));
            }else {
                tvPassProcess.setTextColor(mContext.getResources().getColor(R.color.white));
            }
            Date d1=new Date(productListBean.getStatusTime());
            String  time= DateUtils.formatDataTime(d1);
            tvPassProcess.setText(productListBean.getStatusText()+"\n"+time);
        }else {
            tvPassProcess.setText("");
            tvPassProcess.setTextColor(mContext.getResources().getColor(R.color.white));
        }
        if(!TextUtils.isEmpty(productListBean.getStatusWorkName())){
            tvOperator.setText(productListBean.getStatusWorkName());
        }else {
            tvOperator.setText("");
        }
    }
}
